package com.example.xncs;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * 图片数据类，支持多种图片源
 */
public class ImageData implements Parcelable {
    private String imagePath;      // 图片路径或URI
    private String imageName;      // 图片名称
    private String base64Data;     // base64数据（可选）
    private String sourceApp;      // 来源应用

    public ImageData(String imagePath, String imageName) {
        this.imagePath = imagePath;
        this.imageName = imageName;
    }

    public ImageData(String imagePath, String imageName, String base64Data) {
        this.imagePath = imagePath;
        this.imageName = imageName;
        this.base64Data = base64Data;
    }

    public ImageData(String imagePath, String imageName, String base64Data, String sourceApp) {
        this.imagePath = imagePath;
        this.imageName = imageName;
        this.base64Data = base64Data;
        this.sourceApp = sourceApp;
    }

    protected ImageData(Parcel in) {
        imagePath = in.readString();
        imageName = in.readString();
        base64Data = in.readString();
        sourceApp = in.readString();
    }

    public static final Creator<ImageData> CREATOR = new Creator<ImageData>() {
        @Override
        public ImageData createFromParcel(Parcel in) {
            return new ImageData(in);
        }

        @Override
        public ImageData[] newArray(int size) {
            return new ImageData[size];
        }
    };

    // Getters and Setters
    public String getImagePath() {
        return imagePath;
    }

    public void setImagePath(String imagePath) {
        this.imagePath = imagePath;
    }

    public String getImageName() {
        return imageName;
    }

    public void setImageName(String imageName) {
        this.imageName = imageName;
    }

    public String getBase64Data() {
        return base64Data;
    }

    public void setBase64Data(String base64Data) {
        this.base64Data = base64Data;
    }

    public String getSourceApp() {
        return sourceApp;
    }

    public void setSourceApp(String sourceApp) {
        this.sourceApp = sourceApp;
    }

    /**
     * 检查是否有base64数据
     */
    public boolean hasBase64Data() {
        return base64Data != null && !base64Data.isEmpty();
    }

    /**
     * 检查是否是ContentProvider URI
     */
    public boolean isContentProviderUri() {
        return imagePath != null && imagePath.startsWith("content://");
    }

    /**
     * 检查是否是文件路径
     */
    public boolean isFilePath() {
        return imagePath != null && !imagePath.startsWith("content://");
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(imagePath);
        dest.writeString(imageName);
        dest.writeString(base64Data);
        dest.writeString(sourceApp);
    }

    @Override
    public String toString() {
        return "ImageData{" +
                "imagePath='" + imagePath + '\'' +
                ", imageName='" + imageName + '\'' +
                ", hasBase64Data=" + hasBase64Data() +
                ", sourceApp='" + sourceApp + '\'' +
                '}';
    }
}
